package com.david.buffer;

/**
 * @author david.long 2021/8/24 8:53 上午.
 */
public class ReadBuffer {

    private OnReadBufferCallback callback;

    public ReadBuffer(OnReadBufferCallback callback) {
        this.callback = callback;
    }

    /**
     * @param card        -D  card        声卡         默认0
     * @param device      -d  device      设备         默认0
     * @param channels    -c  channels    通道         默认2
     * @param rate        -r  rate        采样率       默认44100
     * @param format      -b  bits        pcm位宽      默认16
     * @param periodSize  -p  periodSize  一次中断的帧数 默认1024
     * @param periodCount -n  periodCount 周期数        默认4
     */
    public native void readBuffer(int card, int device,int channels, int rate, int format, int periodSize,
                                         int periodCount);

    public void readCallback(byte[] buffer) {
        System.out.println(buffer);
    }

    public void logCallback(String msg) {
        callback.onLog(msg);
    }

    public interface OnReadBufferCallback {
        void onLog(String msg);
    }
}
